s = serial('COM8');
set(s,'BaudRate',38400);
set(s,'DataBits',8);
set(s,'StopBits',1);

fopen(s);

kp_roll = 3;
ki_roll = 1;
kd_roll = 0.3*kp_roll;

kp_pitch = 7;
ki_pitch = 1;
kd_pitch = 0.25*kp_pitch;

kp_yaw = 0*10;
ki_yaw = 0*1;
kd_yaw = 0*0.2*kp_yaw;

RDATA = [mod(kp_roll*10 + 32768, 256) floor(mod((kp_roll*10 +32768)/256, 256))];
RDATA = [RDATA mod(ki_roll*10 + 32768, 256) floor(mod((ki_roll*10 +32768)/256, 256))];
RDATA = [RDATA mod(kd_roll*10 + 32768, 256) floor(mod((kd_roll*10 +32768)/256, 256))];

PDATA = [mod(kp_pitch*10 + 32768, 256) floor(mod((kp_pitch*10 +32768)/256, 256))];
PDATA = [PDATA mod(ki_pitch*10 + 32768, 256) floor(mod((ki_pitch*10 +32768)/256, 256))];
PDATA = [PDATA mod(kd_pitch*10 + 32768, 256) floor(mod((kd_pitch*10 +32768)/256, 256))];

YDATA = [mod(kp_yaw*10 + 32768, 256) floor(mod((kp_yaw*10 +32768)/256, 256))];
YDATA = [YDATA mod(ki_yaw*10 + 32768, 256) floor(mod((ki_yaw*10 +32768)/256, 256))];
YDATA = [YDATA mod(kd_yaw*10 + 32768, 256) floor(mod((kd_yaw*10 +32768)/256, 256))];

DATA = [82 RDATA 80 PDATA 89 YDATA]

fwrite(s, DATA, 'uint8');

fclose(s)